<template>
    <div>
        <h2>食谱信息管理</h2>
        <a href='/AddView'>新增</a><br>
        食谱标题<input type="text" v-model="qag.name">
        分类<select v-model="qag.fent">
                <option value="">请选择</option>
                <option value="早餐">早餐</option>
                <option value="午餐">午餐</option>
                <option value="晚餐">晚餐</option>
            </select>
            <input type="button" value="查询" @click="Show">
        <table>
            <thead>
                <tr>
                    <td>食谱标题</td>
                    <td>分类</td>
                    <td>标签</td>
                    <td>图片</td>
                    <td>食谱详情</td>
                </tr>
            </thead>
            <tbody>
                <tr v-for="m in data">
                    <td>{{ m. name}}</td>
                    <td>{{ m. fent}}</td>
                    <td>{{ m. benr}}</td>
                    <td> <img v-if="m.img" :src="'https://localhost:7172/'+m.img" alt="" style="width: 80px;height: 80px;"></td>
                    <td>{{ m. ment}}</td>
                </tr>
            </tbody>
        </table>
        <input type="button" value="首页" @click="Fent(1)">
        <input type="button" value="上一页" @click="Fent(2)">
        <input type="button" value="下一页" @click="Fent(3)">
        <input type="button" value="尾页" @click="Fent(4)">
        一共{{ page.pcount }}页，一共{{ page.count }}条，每页{{ qag.parsize }}条，当前的{{ qag.pardex }}页
        <select v-model="qag.parsize" @change="setsize">
            <option>2</option>
            <option>4</option>
            <option>6</option>
        </select>
        <input type="text" v-model="qag.pardex">
        <input type="button" value="跳转" @click="setdex">
    </div>
</template>

<script setup lang="ts">
import {ref,onMounted} from 'vue';
import axios from 'axios';

onMounted(() => {
    Show()  
})

const data=ref([{
  "id": 0,
  "name": "",
  "fent": "",
  "benr": "",
  "img": "",
  "ment": ""
}])

const setdex=()=>{
    if(qag.value.pardex>=1&&qag.value.pardex<=page.value.pcount){
        Show()
    }
}

const setsize=()=>{
     qag.value.pardex=1;
     Show()
}

const Fent=(val:any)=>{
    if(val==1){
        qag.value.pardex=1;
        Show();
    }
    if(val==2){
        if(qag.value.pardex>1){
            qag.value.pardex-=1;
            Show();
        }   
    }
    if(val==3){
        if(qag.value.pardex<page.value.pcount){
            qag.value.pardex+=1;
            Show();
        }
    }
    if(val==4){
        qag.value.pardex=page.value.pcount;
        Show();
    }
}

const qag=ref({
    pardex:1,
    parsize:2,
    name:"",
    fent:""
})

const page=ref({
    count:0,
    pcount:0
})

const Show=()=>{
    axios.get("https://localhost:7172/api/User/Show",{params:qag.value}).then(res=>{
        data.value=res.data.data;
        page.value.count=res.data.count;
        page.value.pcount=Math.ceil(page.value.count/qag.value.parsize);
    })
}


</script>

<style scoped>

</style>